<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('退回本单位审核工单T')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            工单编号：<input type="text" name="workFormNo"/>
                        </li>
                        <li>
                            派发单位：<input type="text" name="sdeptName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm " id="toolbar" role="group">
            <a class="btn btn-success single disabled" onclick="detail()">
                <i class="fa"></i> 查看
            </a>
            <a class="btn btn-primary single disabled" onclick="recall('')">
                <i class="fa"></i> 撤回
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:src="@{/common/js/common.js?a=100}"></script>
<script th:inline="javascript">
    var prefix = ctx + "gaoxin/system/mTelWF";
    var mInterior = ctx + "system/mInterior";
    $(function () {
        var options = {
            url: prefix + "/cmnFile/backPeerDeptAuditTJson",
            sortName: "myPkVal",
            sortOrder: "desc",
            uniqueId: "myPkVal",
            modalName: "退回本级工单T",
            fixedColumns: true,
            fixedNumber: 2,
            fixedRightNumber: 1,
            columns: [{
                checkbox: true
            },
                {
                    field: '', title: '序号', align: "center", width: 40, formatter: function (value, row, index) {
                        return serialNumber(value, row, index);
                    }
                },
                {field: 'myPkVal', title: 'pkId', hidden: true, visible: false},
                {field: 'WfId', title: 'wfId', hidden: true, visible: false},
                {field: 'telId', title: 'telId', hidden: true, visible: false},
                {field: 'myTwfNO', title: '工单编号', align: 'center', sortable: true},
                {field: 'myTwfTopic', title: '工单主题', align: 'center', sortable: true, cellStyle: cellEllipsis},
                {field: 'SeqName', title: '交办次序', align: 'center'},
                {field: 'SortName', title: '性质', align: 'center', sortable: true},
                {field: 'DealName', title: '办理方式', align: 'center', hidden: true},
                {field: 'bkLimit', title: '办理期限', align: 'center', sortable: true, width: 80},
                {field: 'SDeptName', title: '来自', align: 'center', hidden: true},
                {field: 'sdDate', title: '派发日期', align: 'center', width: 80},
                {field: 'bkDate', title: '退回日期', align: 'center', width: 80},
                {field: 'BackRemark', title: '退回理由', align: 'center', width: 80, cellStyle: cellEllipsis},
                {
                    field: 'backState',
                    title: '退回状态',
                    align: 'center',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return fmtSBBackCheck(value, row, index);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.backState === 21) {
                            actions.push('<a class="btn btn-default btn-xs " style="cursor: not-allowed;" href="javascript:void(0)" ><i class="fa"></i>撤回</a>');
                        } else {
                            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="recall(' + row.myPkVal + ')" "><i class="fa"></i>撤回</a>&nbsp;');
                            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="auditPeerBack(' + row.myPkVal + ')" "><i class="fa"></i>审查</a>');
                        }
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });

    //查看退回的工单详情
    function detail() {
        let row = $("#bootstrap-table").bootstrapTable('getSelections');
        var wfId = row[0].WfId;
        if (wfId) {
            var url = ctx + "gaoxin/system/test/caseDetail/" + wfId;
            var title = "已退回工单详情";
            $.modal.openTab(title, url);
        }
    }

    //撤回已退回的工单（由本部门或下级部门处理）
    function recall(id) {
        if (id === '') {
            let row = $("#bootstrap-table").bootstrapTable('getSelections');
            id = row[0].myPkVal;
        }
        var url = prefix + "/cmnFile/dlRegetS?sendId=" + id;
        var title = "撤回已退回工单";
        $.modal.openTab(title, url);
    }

    // 审核本级退回
    function auditPeerBack(pkId) {
        if (!pkId) {
            var row = $("#bootstrap-table").bootstrapTable('getSelections');
            pkId = row[0].myPkVal;
        }
        var url = prefix + "/cmnFile/auditPeerBackT/" + pkId;
        $.modal.openTab('退回本级工单审核', url);
    }
</script>
</body>
</html>